<?php
namespace Member\Logic;

/**
 * 配置信息表
 * @author 敏
 *
 */
class ConfigLogic extends BaseLogic {
	
	/**
	 * 查询单条信息
	 * @param unknown $map
	 * @param unknown $field
	 */
	public function info($map,$field = array('id','type')){
	    $info = $this->where($map)->field($field)->find();
	    
	    if(isset($info['config'])){
	    	$info['config'] = serializeMysql($info['config'],1);
	    }
	    return $info;
	}
	
	/* !CodeTemplates.overridecomment.nonjd!
	 * @see \Member\Logic\BaseLogic::update()
	 */
	public function update($data = array(),$map = array('uid'=>UID)) {
		
		if(empty($data)){
			$data = $this->create();
		}
		
		if($data === false){
			return false;
		}
		
// 		$info = $this->where($map)->find();
		$info = $this->isexists($map);
		
		/* 添加或更新数据 */
		if($info === false){//新增数据
			$data['uid'] = UID;
			$id = $this->add($data);
			if(!$id){
				$this->error = '新增内容失败！';
				return false;
			}
			return $id;
			
		} else { //更新数据
			$status = $this->where(array('id'=>$info['id']))->save($data);
			if(false === $status){
				$this->error = '更新内容失败！';
				return false;
			}
		}
		
		return true;
		
	}


	public function allLists($map = array('uid'=>UID,'type'=>'reserve_list')){
		$data = $this->where($map)->order('id DESC')->select();
		foreach ($data as $key => $value){
			$data[$key]['title'] = serializeMysql($value['config'],1)['keywords'];
		}
		return $data;
			
	}
	
	/* !CodeTemplates.overridecomment.nonjd!
	 * @see \Member\Logic\BaseLogic::autoSave()
	 */
	public function autoSave($id = 0) {
		// TODO 自动生成的方法存根
		
	}

	
}